﻿@page "/UserInfoAdd"
@using Carlife.Inf;
@using ICarlifeService;
@using Models;
@using Microsoft.EntityFrameworkCore;
@using Models.Authority;
@inject IDbContextFactory<CarlifeDbcontext> dbFactory;
@inject IUsersService userinfo;
@inject NavigationManager NavigationManager
@inject IJSRuntime jsRuntime
<h3>用户添加</h3>
<PageTitle>用户添加</PageTitle>
<p>
    登录帐号 ：
    <input @bind="@users.Login_Name" type="text"></input>
</p>
<p>
    用户名称：
    <input @bind="@users.UserName" type="text"></input>
</p>
<p>
    密码：
    <input @bind="@users.Password" type="password"></input>
</p>
<p>
    真实姓名：
    <input @bind="@users.RealName" type="text"></input>
</p>
<p>
    英文名称：
    <input @bind="@users.EnglishName" type="text"></input>
</p>
<p>
    性别：
    <input type="radio" @bind="@users.Gender" name="sex" checked="checked">男
    <input type="radio" @bind="@users.Gender" name="sex">女
</p>
<p>
    国际电话：
    <input @bind="@users.Phone" type="text"></input>
</p>
<p>
    移动电话：
    <input @bind="@users.Mobile" type="text"></input>
</p>
<p>
    邮箱：
    <input @bind="@users.Email" type="text"></input>
</p>
<p>
    启用禁用：
    <input type="radio" @bind="@users.Enabled" name="qy" checked="checked">启用
    <input type="radio" @bind="@users.Enabled" name="qy" />禁用
</p>
<p>
    状态：
    <input type="radio" @bind-value="@users.Type" name="zt" checked="checked">在线
    <input type="radio" @bind-value="@users.Type" name="zt">离线
    <input type="radio" @bind-value="@users.Type" name="zt">影身
    <input type="radio" @bind-value="@users.Type" name="zt">请勿打扰
</p>
<div>@Message</div>
<input type="submit" class="btn btn-primary" @onclick="Save" />
@code {
    private string Message = string.Empty;
    private static CarlifeDbcontext _context;
    private Users users = new Users();
    protected override Task OnInitializedAsync()
    {
        _context = dbFactory.CreateDbContext();
        return base.OnInitializedAsync();
    }
    private async void Save()
    {
        users.IsData = true;
        users.DropID = 1;
        int count = userinfo.GetUserAdd(users);
        if (count > 0)
        {
            await jsRuntime.InvokeAsync<string>("alert", "保存成功 !");
            NavigationManager.NavigateTo($"UserIndex");
            StateHasChanged();
        }
        else
        {
            await jsRuntime.InvokeAsync<string>("alert", "保存失败 !");
        }
    }
}
